<div class="modal fade bs-modal-lg" id="modelContent">
	<div class="modal-dialog modal-lg">
        <div class="modal-content"></div>
    </div>
</div>
<div class="portlet box green">
	<div class="portlet-title">
	    <div class="caption"><i class="fa fa-cog"></i>议价单管理 > 待审核议价单 </div>
		<div class="tools">
			<a href="javascript:;" class="collapse right" data-original-title="" title=""> </a>
    	</div>
    	<div class="actions">
			<a href="javascript:;" class="btn white btn-sm ajax-search"><i class="fa fa-search"></i> 查询 </a>
			<a href="javascript:;" class="btn white btn-sm search-reset"><i class="fa fa-eraser"></i> 清除 </a>
		</div>
	</div>
	<div class="portlet-body form">
	   	<form action="/quotation/checkList" class="form-horizontal" method="get" id="searchForm" onsubmit="return false">
	    	<input type="hidden" name="quotationState" value="$!quotationState" >
			<div class="form-body">
				<div class="row">
					<div class="form-group">
						<div class="col-md-3">
							<label class="col-md-4 control-label">企业：</label>
							<div class="col-md-8">
						    	<input type="text" class="form-control"  placeholder="输入企业名称" name="companyName" value="$!companyName">
							</div>
						</div>
						<div class="col-md-3">
							<label class="col-md-4 control-label">会员号：</label>
							<div class="col-md-8">
						    	<input type="text" class="form-control" placeholder="请输入会员号" name="userInfoId" value="$!userInfoId">
							</div>
						</div>
						<div class="col-md-3">
							<label class="control-label col-md-4">报价时间：</label> 
							<label class="col-md-8">
								<input class="form-control" type="text" name="startTime" id="startTime" value="$!startTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
							</label>
						</div>
						<div class="col-md-3">
							<label class="control-label col-md-2">至：</label> 
							<label class="col-md-8">
								<input class="form-control" type="text" name="endTime" id="endTime" value="$!endTime" readonly>
								<i class="fa fa-calendar" style="position: absolute;right: 10px;top: 10px"></i>
							</label>
						</div>
					</div>
					<div class="form-group">
						 <div class="col-md-3">
							<label class="col-md-4 control-label">报价人：</label>
							<div class="col-md-8">
						    	<input type="text" class="form-control" name="operatorName" value="$!operatorName">
							</div>
						</div>
					</div>
	    		</div>
			</div>
		</form>
	</div>
</div>
<div class="portlet box green">
    <div class="portlet-title">
		<div class="caption"><i class="fa fa-cogs"></i>数据列表</div>
		<div class="tools"><a href="javascript:;" class="collapse" data-original-title="" title=""> </a></div>
		<div class="actions">
			<a href="javascript:checkBatchPass();" class="btn white btn-sm"><i class="fa fa-check"></i> 通过 </a>
			<a onclick="javascript:checkBatchDeny(this);" href="" thref="" class="btn white btn-sm ajax-model-get" data-toggle="modal"><i class="fa fa-remove"></i> 拒绝  </a>
		</div>
    </div>
    <div class="portlet-body">
	<div class="form-group">
		<div class="alert alert-warning">
			<strong> 注：</strong> 点击拒绝需要填写原因。
		</div>
	</div>
	<form role="form" action="/quotation/checkBatchPass" class="form-horizontal" method="POST">
		<div class="tabbable-line ">
			<ul class="nav nav-tabs ">
				<li #if(!$quotationState) class="active checkTab" #end> <a href="/quotation/checkList" class="ajaxify"> 全部 </a> </li>
                <li #if($quotationState=='BE_ON_QUOTATION') class="active checkTab" #end> <a href="/quotation/checkList?quotationState=BE_ON_QUOTATION" class="ajaxify"> 审核中 </a> </li>
                <li #if($quotationState=='PASS_QUOTATION') class="active checkTab" #end> <a href="/quotation/checkList?quotationState=PASS_QUOTATION" class="ajaxify"> 审核通过 </a> </li>
                <li #if($quotationState=='DENY_QUOTATION') class="active checkTab" #end> <a href="/quotation/checkList?quotationState=DENY_QUOTATION" class="ajaxify"> 审核拒绝 </a> </li>
			</ul>
			
			<div class="tab-content">
				<div class="tab-pane active form">
					<div class="table-container table-scrollable">
						<table class="table table-bordered table-hover icheck-table" id="productTable">
							<thead>
									<tr>
					  		 			<th style="width: 20px">
											<input type="checkbox" class="icheck group-icheck"/>
										</th>
											<th>议价单号</th>
						  		 			<th>企业名称</th>
						  		 			<th>审核状态</th>
						  		 			<th>会员号</th>
						  		 			<th>申请人</th>
						  		 			<th>手机号</th>
						  		 			<th>审核提示</th>
						  		 			<th>申请时间</th>
						  		 			<th>报价人</th>
						  		 			<th>报价时间</th>
										<th class="col-md-2">操作</th>
									</tr>
								</thead>
								<tbody>
								#foreach($item in $pageQuotation.result)
								#set($userInfo=$userInfoMap.get($item))
								#set($company=$companyMap.get($item))
								#set($operator=$operatorMap.get($item))
						 				<tr>  
									    <td>
									    	<input type="checkbox" name="checkboxes" class="icheck" value="$!item.id" />
								    	</td>
								    	<td>$!item.id</td>
									    <td>$!company.name</td>
									    <td class="quotationState">$!item.quotationState.checkState</td>
									    <td>$!userInfo.id</td>
									    <td>$!userInfo.realname</td>
									    <td>$!userInfo.phone</td>
									    <td class="quotationStateDesc">
									    	#if($item.quotationState=='BE_ON_QUOTATION')
									    		报价单已提交等待审核中
									    	#elseif($item.quotationState=='PASS_QUOTATION')
									    		<label style="color:green">审核通过</label>
									    	#else
									    		<label style="color:red">$!item.denyDetail</label>
									    	#end
									    </td>
									    <td>$!item.timeString</td>
									    <td>$!operator.username</td>
									    <td>$!item.quotationTimeString</td>
						    			<td>
						    				#if($item.quotationState=='BE_ON_QUOTATION')
						    				<a class="btn green btn-outline btn-sm" onclick="javascript:passQuotation(this,'$!item.id');"> 
												<i class="fa fa-check"></i>通过
											</a>
											<a class="btn green btn-outline btn-sm ajax-model-get deny" data-toggle="modal"
												href="#modelContent" thref="/quotation/checkDeny?id=$!item.id"> 
												<i class="fa fa-remove"></i>拒绝
											</a>
											#end
											<a class="btn green btn-outline btn-sm ajaxify" href="/quotation/check?id=$!item.id"> 
												<i class="fa fa-eye"></i>详情
											</a>
									    </td>		  			
						 				</tr>
								#end
								</tbody>
							</table>
					</div>
					#set($page= $pageQuotation)
					#set($pageUrl="/quotation/checkList?$!queryString&pageNo=")
					#parse("_page.htm")
				</div>
			</div>
		</div>
    </form>
    </div>
</div>

<script src="/assets/scripts/views-date.js" type="text/javascript"></script>
<script type="text/javascript" src="/assets/scripts/views-icheck.js"></script>
<script type="text/javascript">
     $("input[name=companyName]").focus();
</script>
<script type="text/javascript">
function passQuotation(obj,id){
	var formData = new FormData();
    formData.append("id", id);
    formData.append("quotationState", "PASS_QUOTATION");
    formData.append("denyDetail", "");
    
	$.ajax({
		url: "/quotation/check",
		type: "POST",
		data: formData,
		contentType: false,
		processData: false,
		dataType: "json",
		success: function(res) {
			if(res.code==0){
				toastr.success(res.msg);
	    		obj.parentNode.parentNode.getElementsByClassName("quotationState")[0].innerHTML='审核通过';
	    		obj.parentNode.parentNode.getElementsByClassName("quotationStateDesc")[0].innerHTML='<label style="color:green">审核通过</label>';
	    		
	    		var nextObj = obj.parentNode.getElementsByClassName("deny")[0];
	    		obj.parentNode.removeChild(nextObj);
	    		obj.parentNode.removeChild(obj); 
			}
		}
	})
}

function checkBatchPass(){
	var params = "";
	$("input[name='checkboxes']").each(function() {
	    if($(this).prop('checked')) {
	        params = params + $(this).val() +",";
	    }
	});
	if(params == ""){
		toastr.warning("批量通过报价单选择为空！");
		return;
	}
	params = params.substring(0,params.length-1);
	
	var formData = new FormData();
    formData.append("checkboxes", params);
	$.ajax({
		url: "/quotation/checkBatchPass",
		type: "POST",
		data: formData,
		contentType: false,
		processData: false,
		dataType: "json",
		success: function(res) {
			if(res.code==0){
				$(".checkTab").eq(0).children("a:eq(0)").click();
				toastr.success(res.msg);
			}
		}
	})
}

function checkBatchDeny(obj){
	var params = "";
	$("input[name='checkboxes']").each(function() {
	    if($(this).prop('checked')) {
	        params = params + $(this).val() +",";
	    }
	});
	if(params == ""){
		toastr.warning("批量拒绝报价单选择为空！");
		return;
	}
	params = params.substring(0,params.length-1);
    
    $(obj).attr("thref","/quotation/checkBatchDeny?checkboxes="+params);
    $(obj).attr("href","#modelContent");
}
</script>